#include "flashitem.h"

flashItem::flashItem()
{
    this->setFlag(ItemIsMovable);       //可移动

    //开启定时器:
    startTimer(1000);
    flag = true;

}

QRectF flashItem::boundingRect() const
{
    return QRectF(-10,-10,40,40);
}

void flashItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    //阴影层：
//    painter->setPen(Qt::NoPen);
//    painter->setBrush(Qt::green);
//    painter->drawEllipse(-7,-7,40,40);


    //椭圆
    painter->setPen(Qt::black);
    painter->setBrush(flag ? Qt::red : Qt::yellow);
    painter->drawEllipse(-10,-10,40,40);

}

void flashItem::timerEvent(QTimerEvent *ev)
{
    flag = !flag;
    update();
}

void flashItem::mousePressEvent(QGraphicsSceneMouseEvent *ev)
{

    this->setCursor(Qt::ClosedHandCursor);
}

void flashItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
    this->setCursor(Qt::OpenHandCursor);
}

void flashItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
    this->setCursor(Qt::OpenHandCursor);
}
